package com.atguigu.system.controller;

import com.atguigu.common.result.Result;
import com.atguigu.common.utils.MD5;
import com.atguigu.model.system.SysPost;
import com.atguigu.model.system.SysUser;
import com.atguigu.model.vo.SysPostQueryVo;
import com.atguigu.model.vo.SysUserQueryVo;
import com.atguigu.system.annotation.Log;
import com.atguigu.system.enums.BusinessType;
import com.atguigu.system.service.SysPostService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author quzengpeng
 * @descpription:
 * @date 2024/4/13
 */
@Api(tags = "岗位管理接口")
@RestController
@RequestMapping("/admin/system/sysPost")
public class SysPostController {

    @Autowired
    private SysPostService sysPostService;

    @ApiOperation("岗位列表")
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       SysPostQueryVo sysPostQueryVo) {
        //创建page对象
        Page<SysPost> pageParam = new Page<>(page,limit);
        //调用service方法
        IPage<SysPost> pageModel = sysPostService.selectPage(pageParam,sysPostQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("添加岗位")
    @Log(title = "添加岗位",businessType = BusinessType.INSERT)
    @PostMapping("save")
    public Result save(@RequestBody SysPost post) {
        boolean is_Success = sysPostService.save(post);
        if(is_Success) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("根据id查询")
    @GetMapping("getPost/{id}")
    public Result getPost(@PathVariable String id) {
        SysPost post = sysPostService.getById(id);
        return Result.ok(post);
    }

    @ApiOperation("修改岗位")
    @Log(title = "修改岗位",businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public Result update(@RequestBody SysPost post) {
        boolean is_Success = sysPostService.updateById(post);
        if(is_Success) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("删除岗位")
    @Log(title = "删除岗位",businessType = BusinessType.DELETE)
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id) {
        boolean is_Success = sysPostService.removeById(id);
        if(is_Success) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}
